package com.erhirent.view;

import java.util.List;

import com.erhairent.tools.InputTools;
import com.erhirent.bean.Car;

public class OrderView extends View {

	@Override
	public View showView() {
		System.out.println("1.预约\t   2.解除预约");
		int book = InputTools.nextInt();
		if (book == 1) {
			// 用户查询上架车辆 不可借 预约车
			List<Car> list = mcar.userqueryPutaway();
			if (list.size() != 0) {
				System.out.println("----------------------------");
				System.out.println("汽车编号\t" + "汽车名称\t" + "备注\t" + "品牌\t" + "类型\t" + "单价\t" + "是否可租\t" + "是否可预约");
				for (Car car : list) {
					System.out.print(car.getcarId() + "\t");
					System.out.print(car.getcarName() + "\t");
					System.out.print(car.getcarRemark() + "\t");
					System.out.print(car.getbrandName() + "\t");
					System.out.print(car.gettypeName() + "\t");
					System.out.print(car.getcarPrice() + "/天\t");
					System.out.print(car.getcarIsrent() + "\t");
					System.out.println(car.getcarIsorder() + "\t");
				}
				System.out.println("----------------------------");
				boolean iscontinue = true;
				for (; iscontinue;) {
					System.out.println("输入你要预约的车辆编号:");
					int x = InputTools.nextInt();
					// 判断该车是否已被预约

					if (mcar.userqueryOrder(x)) {
						if (mcar.carBook(x)) {
							System.out.println("预约成功!");
						} else {
							System.out.println("预约失败");
							showView();
						}
						System.out.println("预约成功!");
						iscontinue = false;
					} else {
						System.out.println("该车已被预约,不可再次预约");
						showView();
					}

				}

			} else if (list.size() == 0) {
				System.out.println("暂无不可租车辆!");
				return mView;
			}

		} else if (book == 2) {
			System.out.println("输入您需要解除预约的汽车编号:");
			int y = InputTools.nextInt();
			if (mcar.clearBook(y)) {
				System.out.println("解除成功!");
			} else {
				System.out.println("解除失败");
			}

		} else {
			System.out.println("输入不存在,重新输入:");
			showView();
		}

		return mView;
	}

}
